WITH a as (select zoom('!scale_denominator!') as current_zoom), b as (SELECT cartodb_id, the_geom_webmercator, date from ov_4_{{table}}, a where current_zoom <4 UNION SELECT cartodb_id,the_geom_webmercator, date from ov_5_{{table}}, a where current_zoom = 4 UNION SELECT cartodb_id,the_geom_webmercator, date from ov_6_{{table}}, a where current_zoom = 5 UNION SELECT cartodb_id,the_geom_webmercator, date from ov_7_{{table}}, a where current_zoom = 6 UNION SELECT cartodb_id,the_geom_webmercator, date from ov_8_{{table}}, a where current_zoom = 7 UNION SELECT cartodb_id,the_geom_webmercator, date from ov_9_{{table}}, a where current_zoom = 8 UNION SELECT cartodb_id,the_geom_webmercator, date from {{table}}, a where current_zoom > 8) SELECT cartodb_id, the_geom_webmercator, to_char(date, 'YYYY-MM-DD') AS date FROM b
